feat: Derive fiat order sourceAmount from on-chain tx data and persist fiat order metadata#8694
Open
OGPoyraz wants to merge 12 commits into
Open
feat: Derive fiat order sourceAmount from on-chain tx data and persist fiat order metadata#8694OGPoyraz wants to merge 12 commits into
OGPoyraz wants to merge 12 commits into
Conversation
…toAmount fallback
sourceAmount from on-chain tx data
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit eb1964b. Configure here.
sourceAmount from on-chain tx data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Explanation
1. Derive fiat order
sourceAmountfrom on-chain tx dataCurrently, the fiat submit flow derives
sourceAmountRawfromorder.cryptoAmount- a human-readable value reported by the on-ramp provider. This value may not precisely reflect what was actually received on-chain.This PR reads the actual transferred amount from the completed on-chain transaction (
order.txHash) instead. For native tokens, the amount is taken fromtx.value. For ERC-20 tokens, the amount is decoded from thetransfer(address,uint256)call data. If the on-chain read fails or the transaction hash is missing, the existingorder.cryptoAmountderivation is used as a fallback.The implementation introduces:
getTransferredAmountFromTxHash- a generic utility inutils/transaction-receipt.tsthat reads transferred amounts from any on-chain transaction (native or ERC-20). Takes explicitchainIdandtokenAddressparams for reusability.resolveSourceAmountRaw- a fiat-strategy-specific function instrategy/fiat/utils.tsthat orchestrates the on-chain read withorder.cryptoAmountfallback.getRawSourceAmountFromOrderCryptoAmount- the existing decimal-shift conversion, moved fromfiat-submit.tstostrategy/fiat/utils.tsand renamed for clarity.2. Persist fiat order metadata on
metamaskPayThe
TransactionPayControllerstate is cleaned up when a transaction is finalized (confirmed/failed/dropped). This meansfiatPayment.orderIdand the provider info are gone by the time the user opens the activity/transaction-details view.To enable the mobile activity view to show a fiat order status row (and query
RampsController:getOrderfor live status), this PR persists the fiat order ID and provider code ontransaction.metamaskPaybefore polling begins insubmitFiatQuotes.Changes:
MetamaskPayMetadata(transaction-controller/types.ts) — AddedfiatOrderId?: stringandfiatProvider?: stringfields.submitFiatQuotes(fiat-submit.ts) — CallsupdateTransactionto persistfiatOrderIdandfiatProviderontx.metamaskPaybeforewaitForOrderCompletionstarts polling. This ensures data is available even while the order is still in-flight.metamaskPayfields are preserved.References
FiatStrategysubmit flow with order polling and relay execution #8347Checklist
Note
Medium Risk
Touches the fiat submission path by introducing on-chain transaction reads and persisting new metadata onto transactions; failures or unexpected tx shapes could affect quote amounts or activity display, though fallbacks and tests mitigate this.
Overview
Improves MetaMask Pay fiat submissions by deriving the relay
sourceAmountRawfrom the completed on-chain transaction (order.txHash) when possible (nativetx.valueor decoded ERC-20transfercalldata), falling back toorder.cryptoAmountif the read fails or is unavailable.Persists fiat on-ramp order identifiers onto the transaction (
transaction.metamaskPay.fiatOrderId/fiatProvider) before order polling begins so downstream activity views can query order status even after controller state cleanup. Adds a reusablegetTransferredAmountFromTxHashutility plus new/updated unit tests and changelog entries.Reviewed by Cursor Bugbot for commit 3535057. Bugbot is set up for automated code reviews on this repo. Configure here.